#include "Parser.h"
#include "ScannerImpl.h"
#include "ParseTree.h"
#include <stdio.h>
#include "Helper.h"
#include "CodeMaker.h"

Parser::Parser(const char* const srcFile):
   scanner(new ScannerImpl(srcFile, NULL)),
   tree(NULL),
   rules(new Rules())
{
}

Parser::~Parser(){}

ParseTree* Parser::parse()
{
    rules->setScanner(scanner);
    printf("parsing ...\n");
    tree = rules->PROG();
    printf("type check ...\n");
    tree->typeCheck();
    printf("generate code ...\n");
    CodeMaker::setOutput();
    tree->makeCode();
    return tree;
}

int main(int argc, char** argv)
{
    if(argc < 2) 
    {
        printf("ERROR: Missing parameter\n");
        return 1;
    }
    Parser parser(argv[1]);
    parser.parse();
    return 0;
}
